home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
C
/
Applications
/
Cheat II
/
main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-09-04
|
6KB
|
297 lines
/*****
* main.c for cheat Account
*
*
*****/
#include <stdarg.h>
#include "cheatMenus.h"
#include "cheatrick.h"
#include "cheatWindow.h"
#include "ResRefs.h"
#include "error.h"
#include "main.h"
#include "cheat.h"
#include "cheatpreffile.h"
#include "cheatwich.h"
#include "cheatfile.h"
#define kbreathingroom 100000 // how many k we don't eat with our possibilities list
// some globals 'n shit
char scratch[257];
int gvalsize = 1, ghowfind = 0, shouldclearup = false;
Ptr *gposs;
long gmaxposs = 0, gcurposs = 0;
int timeToQuit = false;
int gInBackground = false;
shortcut **cut;
long gnumcuts = 0;
extern Rect dragRect;
preftype prefs;
void InitMacintosh(void);
void HandleMouseDown (EventRecord *theEvent);
void HandleEvent(void);
/****
* InitMacintosh()
*
* Initialize all the managers & memory
*
****/
void InitMacintosh(void)
{
MaxApplZone();
InitGraf(&thePort);
InitFonts();
FlushEvents(everyEvent, 0);
InitWindows();
InitMenus();
TEInit();
InitDialogs(0L);
InitCursor();
if (DoReadPrefs((Ptr) &prefs, sizeof(preftype)) == sizeof(preftype)) {
}
prefs.shouldpatchbutt = true;
}
// allocate some memory
static void initmemstuff(void)
{
long l;
allocmem();
l = MaxMem(0);
gmaxposs = (l - kbreathingroom)/4;
gposs = (Ptr *) NewPtr(4 * gmaxposs);
verify(gposs);
}
void HandleControlClicks (EventRecord *theEvent, WindowPtr wp)
{
int partcode, result, i;
ControlHandle which;
Point pt = theEvent->where;
Str255 str;
Boolean selected;
Cell cell = {0, 0}, newcell = {0, 0};
SetPort(wp);
GlobalToLocal(&pt); // must have click in local coords before dealing with cntls
if (wp == cheatWindow) {
if (ghowfind == kfindinterrupt)
return; // can't select a process in this case
selected = LGetSelect(true, &cell, plist); // what cell they have selected before click
if (LClick(pt, 0, plist));
// make sure still same
if ((selected != LGetSelect(true, &newcell, plist)) || (selected && (cell.v != newcell.v)))
doStartOver(); // reset our data
}
else if (wp == sheetWindow) {
if (LClick(pt, theEvent->modifiers, slist))
doOpenCheat();
fixshortbuttz();
}
}
void HandleMouseDown (EventRecord *theEvent)
{
WindowPtr theWindow;
int windowCode = FindWindow (theEvent->where, &theWindow);
switch (windowCode)
{
case inSysWindow:
SystemClick (theEvent, theWindow);
break;
case inMenuBar:
// AdjustMenus();
HandleMenu(MenuSelect(theEvent->where));
break;
case inDrag:
if (theWindow == cheatWindow || theWindow == sheetWindow)
DragWindow(theWindow, theEvent->where, &dragRect);
break;
case inContent:
if (theWindow == cheatWindow || theWindow == sheetWindow) {
if (theWindow != FrontWindow())
SelectWindow(theWindow);
else
HandleControlClicks(theEvent, theWindow);
}
break;
case inGoAway:
if (theWindow == cheatWindow &&
TrackGoAway(cheatWindow, theEvent->where))
HideWindow(cheatWindow);
break;
}
}
/* end HandleMouseDown */
/****
* HandleEvent()
*
* The main event dispatcher. This routine should be called
* repeatedly (it handles only one event).
*
*****/
void HandleEvent(void)
{
WindowPtr theWindow;
int ok;
short item;
EventRecord theEvent;
DialogPtr dp;
char c;
short devent;
HiliteMenu(0);
SystemTask(); /* Handle desk accessories */
ok = GetNextEvent (everyEvent, &theEvent);
devent = IsDialogEvent(&theEvent);
if (devent)
if (DialogSelect(&theEvent, &dp, &item))
if (dp == cheatWindow)
switch (item) {
case riSearchButt: searchButtonHit(); break;
case riStartOverButt: doStartOver(); break;
case riChangeButt: doChange(); break;
case riSizeLong: case riSizeInt: case riSizeByte: doSizeChange(item); break;
case riSelecting: case riInterrupting: doRuptOrSelect(item); break;
default: break;
}
else if (dp == sheetWindow)
switch (item) {
case riAddCheat: doAddCheat(); break;
case riRemoveCheat: doRemoveCheat(); break;
case riOpenCheat: doOpenCheat(); break;
case riExportNew: doExportShortcut(knewfile); break;
case riExportAppend: doExportShortcut(kappendnew); break;
case riAppendToOld: doExportShortcut(koldfile); break;
case riImport: doOpenFile(); break;
default: break;
}
if (ok)
switch (theEvent.what)
{
case mouseDown:
HandleMouseDown(&theEvent);
break;
case keyDown:
case autoKey:
if ((theEvent.modifiers & cmdKey) != 0)
{
// AdjustMenus();
// if (!devent)
HandleMenu(MenuKey((char) (theEvent.message & charCodeMask)));
}
else {
c = (char) (theEvent.message & charCodeMask);
HandleKey(c);
}
break;
case updateEvt:
// BeginUpdate(cheatWindow);
theWindow = (WindowPtr) theEvent.message;
if (theWindow == cheatWindow)
DrawCheatWindow();
else if (theWindow == sheetWindow)
DrawSheetWindow();
// EndUpdate(cheatWindow);
break;
case osEvt:
/* 1.02 - must BitAND with 0x0FF to get only low byte */
switch ((theEvent.message >> 24) & 0x0FF) { /* high byte of message */
case suspendResumeMessage: /* suspend/resume is also an activate/deactivate */
gInBackground = (theEvent.message & resumeFlag) == 0;
if (!gInBackground)
InitCursor();
break;
}
break;
case activateEvt:
InvalRect(&cheatWindow->portRect);
InitCursor();
break;
}
}
/* end HandleEvent */
void checkclearup(void)
{
if (shouldclearup) {
shouldclearup = false;
doclearup();
if (ghowfind)
installTMTask(); // reinstall task so more things can happen
}
}
// a completely bogus function that calls some commands so that
// the code segment they reside in gets into memory, in prep for cheatwich
// otherwise, major crash (checking preload doesn't seem to help, but this works)
static void loadthatseg(char *fmt, ...)
{
va_list args;
int len;
char itch[200];
va_start(args, fmt);
len = vsprintf(itch, fmt, args);
va_end(args);
}
main()
{
InitMacintosh();
SetUpMenus();
SetUpWindow();
OpenAppFile();
initmemstuff();
// doInstallTrap();
// installTMTask();
// cheatwich(0);
loadthatseg("hi there");
remembertraps();
do {
HandleEvent();
if (!gInBackground)
refreshProcesses(); // self-regulates to only execute occasionally
checkclearup();
} while (!timeToQuit);
// doRemoveTrap();
removeTMTask();
}
/* end main */